import QtQuick 1.0
import "../../../common/lib/kdeadmouseutils-build-desktop"

/*
 * un widget de lancement simple
 * besoin de setter les properties 
 * ==>launcher
 * ==>imgUrl
 * 
 * produit le signal hideHome()
 */
Item {
     width: 400 //TODO prendre ds la conf
     height: 300
     id:mainItem
     property variant launcher
     property string imgUrl
     signal hideHome()
     
     Rectangle{
      id:backgroundRect
      anchors.fill: parent
      border.color : 'black'
      border.width : parent.activeFocus?5:0
      //color : '#3E606F'
      color:(launcher && launcher.running)? '#FF606F':'transparent'
      radius : 4
      smooth : true
     }
     
     function init(conf,listLaunchers){
	var launcherName = conf.value('launcher');
	console.log('init from conf pour le widget' + launcherName);
	launcher=listLaunchers.getLauncher(launcherName);
	imgUrl=conf.value('imgUrl');
	x=conf.value('x');
	y=conf.value('y');
	console.log('init from conf OK');
     }
     
     Image {
	    id:img
	    width : parent.width - 40
	    height : parent.height - 40
	    anchors.centerIn:parent
	    fillMode: Image.PreserveAspectFit
	    source: mainItem.imgUrl 
	    smooth: true
     }
     
   Timer {
	id:deferDisplay
	interval: 500
	running: false
	repeat: false
	onTriggered: {
	  if(!launcher.running){
	    launcher.launch();
	  }else{
	    launcher.dbusServ.invokeDbusMethod('show',[]);
	  }
	}
    }
    
    Keys.onReturnPressed : {
      event.accepted = true;
      console.log('selected ');
      mainItem.hideHome();
      deferDisplay.start(); //TODO improuve this, why timer ?
      console.log('fin display , defer');
    }
    
}
